<template>
  <div class="home">
    <!-- 头部 -->
    <div class="home_header">
      <div class="header_left">兰博尔国际</div>
      <div class="header_right">
        <van-search placeholder="请输入商家或商品名称" background="black" />
      </div>
    </div>
    <!-- 菜单栏 -->
    <div class="menu_container">
      <div class="menu_wrapper">
        <div class="menu_item" v-for="(item,index) in category" :key="index">
          <img :src="item.icon" alt />
          <div>{{item.name}}</div>
        </div>
      </div>
    </div>
    <!-- 列表数据栏 -->
    <div class="sort_container">

    </div>
    <div class="list_container">
      <div class="list_item" 
      v-for="(item,index) in listItems" :key="index"
      @click="toDetails(item)">
        <div class="item_img">
          <img :src="item.picUrl" alt="">
        </div>
        <div class="item_message">
          <div class="item_title">{{item.shopName}}</div>
          <div class="item_buy">
            月售：{{item.monthSalesTip}}
            {{item.deliveryTimeTip}} 
            </div>
            <div>
              {{item.minPriceTip}} 
              {{item.shippingFeeTip}} 
            </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {};
  },
  computed: {
    category() {
      return this.$store.state.category;
    },
    listItems(){
      return this.$store.state.listItems
    }
  },
  methods:{
    toDetails(item){
      this.$store.dispatch('GET_DETAILS',item)
      this.$router.push('/details')
    }
  },
  mounted() {
    this.$store.dispatch("GET_CATEGORY");
    this.$store.dispatch("GET_LIST_ITEMS");
    this.$store.dispatch("GET_ALL_DETAILS");
  }
};
</script>

<style scoped>
.home {
  width: 100%;
}
.home_header {
  width: 100%;
  height: 64px;
  background-color: black;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
.header_left {
  width: 50%;
  height: 64px;
  color: #fff;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
.header_right {
  width: 50%;
  /* height: 64px; */
}
.menu_container {
  width: 100%;
  /* height: 220px; */
  overflow-x: scroll;
  white-space: nowrap;
}
.menu_wrapper {
  width: 200%;
  display: inline-flex;
  justify-content: flex-start;
  align-items: flex-start;
  flex-wrap: wrap;
}
.menu_item {
  margin-top: 1%;
  width: 9%;
  height: 100%;
  margin-left: 1%;
  font-size: 14px;
}
.menu_item img {
  width: 90%;
}
.sort_container {
  width: 100%;
  height: 30px;
}
.list_container {
  width: 100%;
}
.list_item {
  width: 100%;
  height: 120px;
  background-color: pink;
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 14px;
}
.item_img {
  width: 30%;
}
.item_img img {
  width: 100%;
}
.item_message {
  width: 68%;
}
.item_title {
  font-size: 18px;
}
.item_buy {
  margin: 10px 0px;
}
</style>